//父类Animal
abstract class Animal {
    String name;
    //构造函数
    public Animal(String name) {
        this.name = name;
    }
    //抽象方法makeSound
    public abstract void makeSound();
}
//子类Tiger
class Tiger extends Animal {
    public Tiger() {
        super("Tiger");
    }
    @Override
    public void makeSound() {
        System.out.println(name + "虎啸: 嗷嗷~~~~");
    }
}
//子类Elephant
class Elephant extends Animal {
    public Elephant() {
        super("Elephant");
    }
    @Override
    public void makeSound() {
        System.out.println(name + "象哞：哞~~~~");
    }
}
//子类Fox
class Fox extends Animal {
    public Fox() {
        super("Fox");
    }
    @Override
    public void makeSound() {
        System.out.println(name + "低吼: 吱吱~~~~");
    }
}
//子类Panda
class Panda extends Animal {
    public Panda() {
        super("Panda");
    }
    @Override
    public void makeSound() {
        System.out.println(name + "低嗷: 咕咕~~~~");
    }
}
class Main {
    public static void main(String[] args) {
        //创建动物数组
        Animal[] animals = new Animal[4];
        //使用固定的顺序来替代随机选择
        animals[0] = new Tiger();
        animals[1] = new Elephant();
        animals[2] = new Fox();
        animals[3] = new Panda();
        //调用每个动物的makeSound方法
        for (int i = 0; i < 4; i++) {
            animals[i].makeSound();
        }
    }
}
